package com.zxj.system.controller.exam;


import com.zxj.common.core.controller.BaseController;
import com.zxj.common.core.domain.R;
import com.zxj.common.core.domain.vo.PageVO;
import com.zxj.system.domain.exam.dto.ExamAddDTO;
import com.zxj.system.domain.exam.dto.ExamEditDTO;
import com.zxj.system.domain.exam.dto.ExamQueryPageDTO;
import com.zxj.system.domain.exam.dto.ExamQuestAddDTO;
import com.zxj.system.domain.exam.vo.ExamAddVO;
import com.zxj.system.domain.exam.vo.ExamDetailVO;
import com.zxj.system.domain.exam.vo.ExamVO;
import com.zxj.system.service.exam.IExamService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 竞赛表结构 前端控制器
 * </p>
 *
 * @author zxj2022
 * @since 2024-12-29
 */
@RestController
@RequestMapping("/exam")
@RequiredArgsConstructor
@Slf4j
@Tag(name = "竞赛管理", description = "竞赛管理接口")
public class ExamController extends BaseController {
    private final IExamService examService;


    @GetMapping("/page/list")
    @Operation(summary = "获取竞赛列表", description = "分页查询竞赛列表")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3102", description = "用户不存在")
    @ApiResponse(responseCode = "3103", description = "用户名或密码错误")
    public R<PageVO<ExamVO>> pageQuery(ExamQueryPageDTO examQueryPageDTO) {
        log.info("接收到分页获取竞赛信息请求, 请求参数：{}", examQueryPageDTO);
        return R.ok(examService.pageQuery(examQueryPageDTO));
    }

    @PostMapping("/add")
    @Operation(summary = "添加竞赛基本信息", description = "添加竞赛基本信息")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3102", description = "用户不存在")
    @ApiResponse(responseCode = "3103", description = "用户名或密码错误")
    public R<ExamAddVO> add(@RequestBody ExamAddDTO examAddDTO) {
        log.info("接收到添加竞赛基本信息请求, 请求参数：{}", examAddDTO);
        return R.ok(examService.add(examAddDTO));
    }

    @PostMapping("/question/add")
    @Operation(summary = "为竞赛添加问题", description = "为竞赛添加问题")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3102", description = "用户不存在")
    @ApiResponse(responseCode = "3103", description = "用户名或密码错误")
    public R<Void> questionAdd(@RequestBody ExamQuestAddDTO examQuestAddDTO) {
        log.info("接收到为竞赛添加问题请求, 请求参数：{}", examQuestAddDTO);
        return toR(examService.questionAdd(examQuestAddDTO));
    }

    @DeleteMapping("/question/delete")
    @Operation(summary = "删除竞赛关联的一个问题", description = "删除竞赛关联的一个问题")
    @Parameter(name = "examId", description = "竞赛 ID",in = ParameterIn.QUERY)
    @Parameter(name = "questionId", description = "问题 ID",in = ParameterIn.QUERY)
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3102", description = "用户不存在")
    @ApiResponse(responseCode = "3103", description = "用户名或密码错误")
    public R<Void> questionDelete(Long examId, Long questionId) {
        log.info("接收到删除竞赛关联的一个问题请求, 请求参数：examId={}, questionId={}", examId, questionId);
        return toR(examService.questionDelete(examId, questionId));
    }

    @GetMapping("/{examId}")
    @Operation(summary = "获取竞赛详情", description = "获取竞赛详情")
    @Parameter(name = "examId", description = "竞赛 ID",in = ParameterIn.PATH)
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3102", description = "用户不存在")
    @ApiResponse(responseCode = "3103", description = "用户名或密码错误")
    public R<ExamDetailVO> detail(@PathVariable Long examId) {
        log.info("接收到获取竞赛详情请求, 请求参数：examId={}", examId);
        return R.ok(examService.detail(examId));
    }

    @PutMapping("/edit")
    @Operation(summary = "编辑竞赛基本信息", description = "编辑竞赛基本信息")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3102", description = "用户不存在")
    @ApiResponse(responseCode = "3103", description = "用户名或密码错误")
    public R<Void> edit(@RequestBody ExamEditDTO examEditDTO) {
        return toR(examService.edit(examEditDTO));
    }

    @DeleteMapping("/{examId}")
    @Operation(summary = "删除竞赛", description = "依据ID删除竞赛")
    @Parameter(name = "examId", description = "竞赛 ID",in = ParameterIn.PATH)
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3102", description = "用户不存在")
    @ApiResponse(responseCode = "3103", description = "用户名或密码错误")
    public R<Void> delete(@PathVariable Long examId) {
        log.info("接收到删除竞赛请求, 请求参数：examId={}", examId);
        return toR(examService.delete(examId));
    }

    @PutMapping("/publish")
    @Operation(summary = "发布竞赛", description = "发布竞赛")
    @Parameter(name = "examId", description = "竞赛 ID",in = ParameterIn.QUERY)
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3102", description = "用户不存在")
    @ApiResponse(responseCode = "3103", description = "用户名或密码错误")
    public R<Void> publish(Long examId) {
        log.info("接收到发布竞赛请求, 请求参数：examId={}", examId);
        return toR(examService.publish(examId));
    }

    @PutMapping("/cancelPublish")
    @Operation(summary = "取消发布竞赛", description = "取消发布竞赛")
    @Parameter(name = "examId", description = "竞赛 ID",in = ParameterIn.QUERY)
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3102", description = "用户不存在")
    @ApiResponse(responseCode = "3103", description = "用户名或密码错误")
    public R<Void> cancelPublish(Long examId) {
        log.info("接收到取消发布竞赛请求, 请求参数：examId={}", examId);
        return toR(examService.cancelPublish(examId));
    }
}
